from modelscope.utils.constant import Tasks
from modelscope.pipelines import pipeline
import cv2
import torch

# pipe = AutoModel.from_pretrained('I:/models/xiaoguailin/clip-vit-large-patch14-zip')
pipe = pipeline(task=Tasks.text_to_image_synthesis,
                model='I:\\models\\AI-ModelScope\\stable-diffusion-xl-base-1___0',
                )

prompt = 'in desert,driving red Audi car.'
output = pipe({'text': prompt})
cv2.imwrite('result.png', output['output_imgs'][0])

# pipeline = AutoPipelineForText2Image.from_pretrained(
#     "~/.cache/modelscope/hub/AI-ModelScope/stable-diffusion-xl-base-1___0",
#     enable_pag=True,  ##add
#     pag_applied_layers=["mid"],  ##add
#     torch_dtype=torch.float16
# )
# pipeline.enable_model_cpu_offload()
